namespace TXLooker.WorkItemExtention.WIQL
{
    using System;
    using System.Globalization;
    using System.Resources;
    using System.Reflection;

    public static class ResourceStrings
    {
        public const string ContainsWorksForStringsOnly = "ContainsWorksForStringsOnly";
        public const string DateConstantFormat = "DateConstantFormat";
        public const string DetailedMessage = "DetailedMessage";
        public const string DuplicateAsOf = "DuplicateAsOf";
        public const string DuplicateFrom = "DuplicateFrom";
        public const string DuplicateGroupBy = "DuplicateGroupBy";
        public const string DuplicateOrderBy = "DuplicateOrderBy";
        public const string DuplicateWhere = "DuplicateWhere";
        public const string EverNotEqualOperator = "EverNotEqualOperator";
        public const string EverWithDatePrecision = "EverWithDatePrecision";
        public const string ExpectingBoolean = "ExpectingBoolean";
        public const string ExpectingBy = "ExpectingBy";
        public const string ExpectingClosingQuote = "ExpectingClosingQuote";
        public const string ExpectingClosingSquareBracket = "ExpectingClosingSquareBracket";
        public const string ExpectingComparisonOperator = "ExpectingComparisonOperator";
        public const string ExpectingCondition = "ExpectingCondition";
        public const string ExpectingConst = "ExpectingConst";
        public const string ExpectingDate = "ExpectingDate";
        public const string ExpectingEndOfString = "ExpectingEndOfString";
        public const string ExpectingFieldList = "ExpectingFieldList";
        public const string ExpectingFieldName = "ExpectingFieldName";
        public const string ExpectingLeftBracket = "ExpectingLeftBracket";
        public const string ExpectingRightBracket = "ExpectingRightBracket";
        public const string ExpectingSelect = "ExpectingSelect";
        public const string ExpectingTableName = "ExpectingTableName";
        public const string ExpectingValue = "ExpectingValue";
        public const string FieldDoesNotExistInTheTable = "FieldDoesNotExistInTheTable";
        public const string FromIsNotSpecified = "FromIsNotSpecified";
        public const string GroupByIsNotSupported = "GroupByIsNotSupported";
        public const string IncompatibleRightConst = "IncompatibleRightConst";
        public const string InOperatorWithTreePathField = "InOperatorWithTreePathField";
        public const string InvalidConditionalOperator = "InvalidConditionalOperator";
        public const string InvalidConditionForEmptyString = "InvalidConditionForEmptyString";
        public const string InvalidConditionForLongTextField = "InvalidConditionForLongTextField";
        public const string InvalidConditionForNodeField = "InvalidConditionForNodeField";
        public const string InvalidConditionForTreeField = "InvalidConditionForTreeField";
        public const string InvalidLongTextSearchForWhitespace = "InvalidLongTextSearchForWhitespace";
        public const string InvalidNodeType = "InvalidNodeType";
        public const string InvalidProjectName = "InvalidProjectName";
        private static ResourceManager m_resMgr = new ResourceManager("ResourceStrings", Assembly.GetAssembly(typeof(ResourceStrings)));
        public const string NoError = "NoError";
        public const string NonQueriableNodeField = "NonQueriableNodeField";
        public const string NonQueryableField = "NonQueryableField";
        public const string NonSortableField = "NonSortableField";
        public const string NonZeroTime = "NonZeroTime";
        public const string PathMustBeAStringNotStartingWithBackslash = "PathMustBeAStringNotStartingWithBackslash";
        public const string ProjectNotFound = "ProjectNotFound";
        public const string StringIsNotANumber = "StringIsNotANumber";
        public const string TableDoesNotExist = "TableDoesNotExist";
        public const string TooComplexEverOperator = "TooComplexEverOperator";
        public const string TreePathIsNotFoundInHierarchy = "TreePathIsNotFoundInHierarchy";
        public const string UnderCanBeUsedForTreePathFieldOnly = "UnderCanBeUsedForTreePathFieldOnly";
        public const string UnknownFieldType = "UnknownFieldType";
        public const string UnknownOrIncompatibleTypesInTheList = "UnknownOrIncompatibleTypesInTheList";
        public const string UnknownVariableType = "UnknownVariableType";
        public const string VariableDoesNotExist = "VariableDoesNotExist";
        public const string WrongTypeForArithmetic = "WrongTypeForArithmetic";
        public const string WrongTypeForArithmeticRightOperand = "WrongTypeForArithmeticRightOperand";

        public static string Format(string resourceName, params object[] args)
        {
            string format = Get(resourceName);
            if (args == null)
            {
                return format;
            }
            for (int i = 0; i < args.Length; i++)
            {
                if (args[i] is DateTime)
                {
                    DateTime time = (DateTime) args[i];
                    Calendar calendar = DateTimeFormatInfo.CurrentInfo.Calendar;
                    if (time > calendar.MaxSupportedDateTime)
                    {
                        args[i] = calendar.MaxSupportedDateTime;
                    }
                    else if (time < calendar.MinSupportedDateTime)
                    {
                        args[i] = calendar.MinSupportedDateTime;
                    }
                }
            }
            return string.Format(format, args);
        }

        public static string Get(string resourceName)
        {
            return m_resMgr.GetString(resourceName);
        }

        //public static bool GetBool(string resourceName)
        //{
        //    return (bool) m_resMgr.GetObject(resourceName);
        //}

        //public static int GetInt(string resourceName)
        //{
        //    return (int) m_resMgr.GetObject(resourceName);
        //}

        //public static ResourceManager Manager
        //{
        //    get
        //    {
        //        return m_resMgr;
        //    }
        //}
    }
}

